﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAbstractor;
using DataAbstractorExample.Forms;
using DataAbstractorExample.Models;

namespace DataAbstractorExample
{
    public class DataAbstractorMapping : IDataAbstractorMapping
    {
        public void InitialiseMapping()
        {
            DataAbstractor.DataAbstractor.Map<NoteView, Note>();
            DataAbstractor.DataAbstractor.Map<CommentView, Comment>();
            DataAbstractor.DataAbstractor.Map<NoteEdit, Note>();
            DataAbstractor.DataAbstractor.Map<Note, NoteEdit>()
                .Ignore(i => i.NoteId)
                .Ignore(i => i.Created)
                .Ignore(i => i.Comments)
                .Run((destination, source) =>
                    {
                        if (destination.Created == DateTime.MinValue)
                        {
                            destination.Created = DateTime.Now;
                        }
                    });
            DataAbstractor.DataAbstractor.Map<Comment, CommentAdd>()
                .Ignore(i => i.CommentId)
                .Ignore(i => i.Note);
        }
    }
}